//
//  ST_BTBootController.swift
//  DrinkTogether
//
//  Created by macmini on 23/01/2018.
//  Copyright © 2018 DouLei. All rights reserved.
//

import UIKit
import SwiftyUserDefaults
import SwifterSwift
import SwiftyJSON
import SnapKit
import NIMSDK
import RxCocoa
import RxSwift
import NSObject_Rx


class ST_BTBootController: UIViewController {
    
    // MARK: properties
    static let shared = ST_BTBootController()
    
    @objc static func sharedInstance()->ST_BTBootController{
        return shared
    }
    
    fileprivate lazy var main_controller = ST_BTLaunchController.shared
    
    fileprivate lazy var main_nav_controller:UINavigationController = {
        
        let vc = UINavigationController.create_hiding_bar_navigation_controller(rootViewController: main_controller)
        
        vc.delegate = self
        
        return vc
    }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        if #available(iOS 13.0, *) {
            self.overrideUserInterfaceStyle = .light
        }
        
        init_main_layout()
        
        binding()
        
    }
    
    private func binding(){
        
        SCComponets.login_status_did_changed_observable().distinctUntilChanged().subscribe(onNext: { f in
            print("SCComponets.login_status_did_changed_observable()")
            if f == true{
                self.modify_status_bar_style(darkStyle: true)
                SCComponets.location_component.locate_with_push_to_server()
            }
            
        }).disposed(by: rx.disposeBag)
        
        
        
    }
    
    fileprivate func init_main_layout()  {
        
        self.addChild(main_nav_controller)
        self.view.addSubview(main_nav_controller.view)
        
        main_nav_controller.view.snp.makeConstraints { (make) in
            make.left.top.right.bottom.equalTo(self.view)
        }
        
    }
    
    
    //    MARK: - status bar  Device orientation
    fileprivate var status_bar_dark_style = false
    func modify_status_bar_style(darkStyle:Bool = false)  {
        if status_bar_dark_style != darkStyle{
            status_bar_dark_style = darkStyle
            self.setNeedsStatusBarAppearanceUpdate()
        }
    }
    
    override var preferredStatusBarStyle: UIStatusBarStyle {
        if status_bar_dark_style{
            if #available(iOS 13.0, *) {
                return UIStatusBarStyle.darkContent
            } else {
                return UIStatusBarStyle.default
            }
        }
        return UIStatusBarStyle.lightContent
    }
    
    override var shouldAutorotate: Bool{
        
        return false
    }
    
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask{
        return UIInterfaceOrientationMask.portrait
    }
    
    override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{
        return UIInterfaceOrientation.portrait
    }
    
}

